package android.zhcs.myapplication;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Toast;
import android.zhcs.myapplication.databinding.ActivityMainActivity2zfBinding;
import android.zhcs.myapplication.databinding.Item2Binding;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity2zf extends AppCompatActivity {

    private int sj = 60;
    private ArrayList<bean1> list2;

    public static void start(Context c) {
        Intent intent = new Intent(c, MainActivity2zf.class);
        c.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainActivity2zfBinding binding = ActivityMainActivity2zfBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getSupportActionBar().hide();
        binding.fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        binding.m.setText(sj--+"");
                    }
                });
            }
        };
        timer.schedule(timerTask,0,1000);
        list2 = MainActivity2sy.list2;
        binding.myrec.seta(1, list2.size(), R.layout.item2, new Cal() {
            @Override
            public void bix(View itemView, int position) {
                Item2Binding inflate = Item2Binding.bind(itemView);
                bean1 b = MainActivity2sy.list2.get(position);
                inflate.num.setText(b.num + "份");
                inflate.img.setImageResource(R.mipmap.dbz);
                inflate.jg.setText("￥" + b.jg);
                inflate.name.setText(b.name);
            }
        });
        binding.zf.setText("支付"+MainActivity2sy.zjg + "元");
        binding.zf.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity2zf.this,"支付成功！",Toast.LENGTH_SHORT).show();
                new CountDownTimer(3000,1000) {
                    @Override
                    public void onTick(long l) {

                    }

                    @Override
                    public void onFinish() {
                        MainActivity2zfcg.start(MainActivity2zf.this);
                    }
                }.start();

            }
        });
    }
}